package com.ruoyi.ewem.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.ewem.domain.Ininfo;
import com.ruoyi.ewem.domain.Warehouse;
import com.ruoyi.ewem.service.IninfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 入库记录Controller
 *
 * @author ruoyi
 * @date 2024-07-27
 */
@RestController
@RequestMapping("/ininfo")
public class IninfoController extends BaseController {
    @Autowired
    private IninfoService ininfoService;

    /**
     * 查询入库记录列表
     */
    @RequiresPermissions("ewem:ininfo:list")
    @GetMapping("/list")
    public TableDataInfo list(Ininfo ininfo) {
        startPage();
        List<Ininfo> list = ininfoService.selectIninfoList(ininfo);
        return getDataTable(list);
    }

    /**
     * 入库 签收
     */
    @PutMapping("/stockIn")
    public AjaxResult stockIn(@RequestBody Ininfo inInfo){
        return toAjax(ininfoService.updateIninfo(inInfo));
    }

    /**
     * 导出入库记录列表
     */
    @RequiresPermissions("ewem:ininfo:export")
    @Log(title = "入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Ininfo ininfo) {
        List<Ininfo> list = ininfoService.selectIninfoList(ininfo);
        ExcelUtil<Ininfo> util = new ExcelUtil<Ininfo>(Ininfo.class);
        util.exportExcel(response, list, "入库记录数据");
    }

    /**
     * 获取入库记录详细信息
     */
    @RequiresPermissions("ewem:ininfo:query")
    @GetMapping(value = "/{ininfoId}")
    public AjaxResult getInfo(@PathVariable("ininfoId") Long ininfoId) {
        return success(ininfoService.getById(ininfoId));
    }

    /**
     * 新增入库记录
     */
    @RequiresPermissions("ewem:ininfo:add")
    @Log(title = "入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Ininfo ininfo) {
        return toAjax(ininfoService.save(ininfo));
    }

    /**
     * 修改入库记录
     */
    @RequiresPermissions("ewem:ininfo:edit")
    @Log(title = "入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Ininfo ininfo) {
        return toAjax(ininfoService.updateById(ininfo));
    }

    /**
     * 删除入库记录
     */
    @RequiresPermissions("ewem:ininfo:remove")
    @Log(title = "入库记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ininfoIds}")
    public AjaxResult remove(@PathVariable Long[] ininfoIds) {
        return toAjax(ininfoService.removeBatchByIds(Arrays.asList(ininfoIds)));
    }
}
